	$(function(){
		var lineChart = echarts.init(document.getElementById("incomeChart"),"customed");
		$.getJSON("/gradesign/income/incomeChart",function(data){
			lineChart.setOption(data.option);
		});
		initDataGrid();
	});
	function initDataGrid(){
		//创建bootstraptable
		$("#dataGrid").bootstrapTable({
			method:"get",
			cache: false,         
			//缺失无法执行queryParams,传递Page参数
			contentType : "application/x-www-form-urlencoded",
			dataType : "json",
			url : "/gradesign/income/query",
			queryParams : queryParam,
			pagination : true,//显示分页条：页码，条数等
			striped : true,//隔行变色
			pageNumber : 1,//首页页码
			pageSize : 5,//分页，页面数据条数
			pageList: [10, 18, 27, 36],
			uniqueId : "id",//Indicate an unique identifier for each row
			sidePagination : "server",//在服务器端分页
			height:dataGrid.height,
			sortName : "date",
			toolbar : "#toolbar",//工具栏
			columns : [{
				checkbox : "true",
				field : "box",
				width : 50
			},{
				title : "Id",
				field : "id",
				visible : false
			},{
				title : "收入项目",
				field : "item"
			},{
				title : "收入日期",
				field : "date",
				sortable : true
			},{
				title : "收入金额",
				field : "money"
			},{
				title : "收入人",
				field : "member"
			},{
				title : "收入类型",
				field : "type"
			},{
				title : "收入类型详细",
				field : "typeDetail"
			},{
				title : "备注",
				field : "tip"
			}],
			search : true,
			searchOnEnterkey : true,
			showRefresh : true,
			showToggle : true
		});
	}
	function queryParam(params){
		var param = {
				limit : this.limit,//页面大小
				offset : this.offset,//页码
				pageNumber : this.pageNumber,
				pageSize : this.pageSize,
				sortName : this.sortName,
				sortOrder : this.sortOrder
		};
		return param;
	}
	$("#incomeType").change(function () {
	    var index = $(this).get(0).selectedIndex;
//	    $('.incomeTypeDetail').hide().eq(index).show();
	    $('.incomeDiv').hide().eq(index).show();
	});
	$("#incomeTypeEdit").change(function () {
	    var index = $(this).get(0).selectedIndex;
//	    $('.incomeTypeDetailEdit').hide().eq(index).show();
	    $('.incomeDivEdit').hide().eq(index).show();
	});
	$(document).ready(function(){
		$(".select-first").show();
	})
	//添加收入记录
	function submit() {
	   var params = {};
	   params.incomeItem = $("#incomeItem").val();
	   params.incomeDate = $("#incomeDate").val();
	   params.incomeType = $("#incomeType").val();
	   if($("#incomeType").val()=="劳动收入"){
		   params.incomeTypeDetail = $("#incomeWorkDetail").val();
	   }else if($("#incomeType").val()=="理财收入"){
		   params.incomeTypeDetail = $("#incomeFinancialDetail").val();
	   }else if($("#incomeType").val()=="其他收入"){
		   params.incomeTypeDetail = $("#incomeOtherDetail").val();
	   }else{
		   params.incomeTypeDetail = "";
	   }
	   params.incomeMember = $("#incomeMember").val();
	   params.incomeMoney = $("#incomeMoney").val();
	   params.incomeTip = $("#incomeTip").val();
	   $.ajax({
		   url : "/gradesign/income/addItem",
		   data : params,
		   method : "post",
		   dataType : "json",
		   success : function(res){
			   if(res.result=="success"){
				   alert("收入项目添加成功！");
				   document.getElementById("incomeModalForm").reset();
				   $("#addIncomeModal").modal('hide');
				   $("#dataGrid").bootstrapTable('refresh');
			   }else{
				   alert("收入项目添加失败！");
			   }
		   },error : function(){
			   alert("系统错误，请联系管理员");
		   }
	   });
	};
	//删除收入记录
	function deleteIncomeItem(){
		var rows = $("#dataGrid").bootstrapTable("getSelections");
		if(rows.length==0){
			alert("请先选中记录！");
		}else{
			var ids = [];
			for(var i = 0;i < rows.length;i++){
				ids.push(rows[i].id);
			}
			$.ajax({
				url : "/gradesign/income/delete",
				dataType:"json",
				traditional: true,//属性在这里设置
				method:"post",
				data:{
					"ids":ids
				},
				success : function(){
					$("#dataGrid").bootstrapTable("refresh");
					alert("删除成功！");
				},
				error : function(){
					alert("系统错误！");
				}
			})
		}
	};
	//点击修改收入项按钮，判断是否有选中行，然后弹出模态框，并赋值
	function editIncomeItem(){
		var row = $("#dataGrid").bootstrapTable("getSelections");
		if(row.length==0){
			alert("请选中要修改的收入项！");
		}else if(row.length==1){
			$('#editIncomeModal').modal('show');
			$('#idEdit').val(row[0].id);
			$('#incomeItemEdit').val(row[0].item);
			$('#incomeDateEdit').val(row[0].date);
			$('#incomeMoneyEdit').val(row[0].money);
			$('#incomeMemberEdit').val(row[0].member);
			$('#incomeTypeEdit').val(row[0].type);
			if(row[0].type=="劳动收入"){
				$(".firstEdit").show();
				$(".secondEdit").hide();
				$(".thirdEdit").hide();
				$('#incomeWorkDetailEdit').val(row[0].typeDetail);
			}else if(row[0].type=="理财收入"){
				$(".firstEdit").hide();
				$(".secondEdit").show();
				$(".thirdEdit").hide();
				$('#incomeFinancialDetailEdit').val(row[0].typeDetail);
			}else if(row[0].type=="其他收入"){
				$(".firstEdit").hide();
				$(".secondEdit").hide();
				$(".thirdEdit").show();
				$('#incomeOtherDetailEdit').val(row[0].typeDetail);
			};
			$('#incomeTipEdit').val(row[0].tip);
		}else{
			alert("请选中一行要修改的收入项！");
		}
		
	}
	function edit(){
		var params = {};
		   params.id = $("#idEdit").val();
		   params.incomeItem = $("#incomeItemEdit").val();
		   params.incomeDate = $("#incomeDateEdit").val();
		   params.incomeType = $("#incomeTypeEdit").val();
		   if($("#incomeTypeEdit").val()=="劳动收入"){
			   params.incomeTypeDetail = $("#incomeWorkDetailEdit").val();
		   }else if($("#incomeTypeEdit").val()=="理财收入"){
			   params.incomeTypeDetail = $("#incomeFinancialDetailEdit").val();
		   }else if($("#incomeTypeEdit").val()=="其他收入"){
			   params.incomeTypeDetail = $("#incomeOtherDetailEdit").val();
		   }else{
			   params.incomeTypeDetail = "";
		   }
		   params.incomeMember = $("#incomeMemberEdit").val();
		   params.incomeMoney = $("#incomeMoneyEdit").val();
		   params.incomeTip = $("#incomeTipEdit").val();
		   $.ajax({
			   url : "/gradesign/income/updateItem",
			   data : params,
			   method : "post",
			   dataType : "json",
			   success : function(res){
				   if(res.result=="success"){
					   alert("收入项目修改成功！");
					   document.getElementById("incomeEditModalForm").reset();
					   $("#editIncomeModal").modal('hide');
					   $("#dataGrid").bootstrapTable('refresh');
				   }else{
					   alert("收入项目修改失败！");
				   }
			   },error : function(){
				   alert("系统错误，请联系管理员");
			   }
		   });
	}
	$('#datetimepicker').datetimepicker({
	    language:  'zh-CN',
	    weekStart: 1,
	    todayBtn:  1,
	    autoclose: 1,
	    todayHighlight: 1,
	    startView: 2,
	    minView: 2,
	    forceParse: 0,
	    todayHighlight: true
	});
	$('#datetimepickerEdit').datetimepicker({
	    language:  'zh-CN',
	    weekStart: 1,
	    todayBtn:  1,
	    autoclose: 1,
	    todayHighlight: 1,
	    startView: 2,
	    minView: 2,
	    forceParse: 0,
	    todayHighlight: true
	});
	//点击取消后清空表单中已写信息
	function resetIncomeModal(){
		document.getElementById("incomeModalForm").reset();
	};
